<template>
  <div class="map-box">
    <el-input
      v-model="value[2]"
      size="small"
      clearable
      placeholder="请选择地图"
      @focus="visible = true"
    ></el-input>
    <ComDialog
      ref="comDialog"
      :option="option"
      :visible.sync="visible"
      @on-submit="onSubmit"
    >
    999
      <!-- <div v-if="visible" id="container"></div> -->
    </ComDialog>
  </div>
</template>
 
<script>
import AMapLoader from "@amap/amap-jsapi-loader";
import ComDialog from "./com-dialog.vue";

export default {
  name: "comInputMap",
  components: { ComDialog },
  
  data() {
    return {
      mapData: {},
      value: [116.4012765, 39.9235306],
      visible: false,
      option: {
        title: "请选择地图", // 标题
        width: "75%",
      },
    };
  },
  created() {
    if (this.form.length > 0) this.value = this.form;
  },
  mounted() {
    //DOM初始化完成进行地图初始化
    // this.initMap();
  },
  methods: {
    initMap() {
      AMapLoader.load({
        key: "ad6573a83001086be31c64ff72008dcd", // 申请好的Web端开发者Key，首次调用 load 时必填
        version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
        plugins: [""], // 需要使用的的插件列表，如比例尺'AMap.Scale'等
      })
        .then((AMap) => {
          console.log(this.value);
          this.map = new AMap.Map("container", {
            //设置地图容器id
            viewMode: "3D", //是否为3D地图模式
            center: this.value, //初始化地图中心点位置
            ...this.params, // 高德初始化参数
          });
        })
        .catch((e) => {
          console.log(e);
        });
    },
    onSubmit(done, loading) {
      setTimeout(() => {
        this.$message({
          type: "success",
          message: "提交成功",
        });
        done();
        // loading();
      }, 2000);
    },
  },
};
</script>
 
<style scoped lang = "less">
#container {
  position: relative;
  padding: 0px;
  margin: 0px;
  width: 100%;
  height: 400px;
}
</style>